package com.logistic;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.json.annotations.JSON;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;










import com.Entity.Visitor.Visitor;
import com.Entity.Visitor.VisitorImplement;
//import com.DAO.User;
import com.opensymphony.xwork2.ActionSupport;

public abstract class Basic extends ActionSupport implements ServletRequestAware
//implements ServletRequestAware
{
	private static final long serialVersionUID = 1L;
	/**
	 * @Title Basic.java
	 * @Package com.logistic
	 * @author ufo
	 */

	protected HttpServletRequest request;
	protected VisitorImplement visitor;
	protected Map<String,String> result=new HashMap<String,String>();

	protected final static String PRODUCT_KEYNAME_OWNER="owner";

	public void finalize() throws Throwable{
//		hibernateSess.close();
		super.finalize();
	}

	public boolean isOnline(){
		return null!=request.getSession().getAttribute("visitorName");
	}

	public void addVisitorToSession(String visitorName,String password){
		request.getSession().setAttribute("visitorName",visitorName);
		request.getSession().setAttribute("password", password);
	}

	public void addSessionToVisitor(){
		this.visitor=new Visitor((String)request.getSession().getAttribute("visitorName"),
				(String)request.getSession().getAttribute("password"));
	}

	@JSON(name="result")
	abstract public Map<String,String> getResult();
	public void setResult(Map<String, String> result){
		this.result=result;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		// TODO 自动生成的方法存根
		this.request=request;
		try {
			this.request.setCharacterEncoding("UTF8");
		} catch (UnsupportedEncodingException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
	}
}
